package com.gitee.feizns.quickstart.ding.talk.spring.boot.autoconfigure;

import com.gitee.feizns.quickstart.ding.talk.api.top.api.ContactsApi;
import com.gitee.feizns.quickstart.ding.talk.spring.boot.autoconfigure.db.mybatis.flex.ContactsSynchronizer;
import com.mybatisflex.core.activerecord.Model;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;

import javax.persistence.Entity;

/**
 * mybatis-flex 钉钉数据库自动配置
 * @author feizns
 * @since 2025/9/24
 */
@AutoConfiguration
@ConditionalOnClass({Entity.class, Model.class})
@ConditionalOnProperty(prefix = "quickstart.ding-talk", name = "auto-synchronize", havingValue = "true")
@EntityScan("com.gitee.feizns.quickstart.ding.talk.spring.boot.autoconfigure.db.mybatis.flex.pojo")
@MapperScan("com.gitee.feizns.quickstart.ding.talk.spring.boot.autoconfigure.db.mybatis.flex.mapper")
public class MybatisFlexDdDbAutoConfigure {

    /**
     * 联系人同步器
     * @param contactsApi 联系人 API
     * @return {@link ContactsSynchronizer }
     */
    @Bean
    @ConditionalOnMissingBean
    public ContactsSynchronizer contactsSynchronizer(ContactsApi contactsApi) {
        return new ContactsSynchronizer(contactsApi);
    }

}
